package com.shujia.kafka;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;

import java.util.Properties;

/**
 * @author shujia
 */
public class Demo1Producer {
    public static void main(String[] args) {
        //擦黄健配置文件对象
        Properties properties = new Properties();
        //设置broker列表
        properties.setProperty("bootstrap.servers", "master:9092,node2:9092,node2:9092");

        //对数据进行序列化的类，String
        properties.setProperty("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        properties.setProperty("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");

        //创建kafka生产者
        KafkaProducer<String, String> kafkaProducer = new KafkaProducer<>(properties);

        //创建一行数据，执行topic和数据
        ProducerRecord<String, String> producerRecord = new ProducerRecord<>("bigdata", "大数据");

        //生产数据
        kafkaProducer.send(producerRecord);

        //关闭连接
        kafkaProducer.close();
    }
}
